﻿namespace SystemWrapper.Tests.Security.Certificate
// ReSharper disable InconsistentNaming
// ReSharper disable AccessToStaticMemberViaDerivedType
// ReSharper disable SealedMemberInSealedClass
{
    using System.Security.Cryptography.X509Certificates;

    using SystemInterface.Security.Certificate;

    using SystemWrapper.Security.Certificate;

    using NUnit.Framework;

    using Testeroids;

    public abstract class X509ChainElementCollectionFactorySpecs
    {
        public abstract class given_instantiated_Sut : ContextSpecification<X509ChainElementCollectionFactory>
        {
            #region Context

            protected override X509ChainElementCollectionFactory CreateSubjectUnderTest()
            {
                return new X509ChainElementCollectionFactory();
            }

            #endregion

            public sealed class when_Create_is_called_without_parameter : given_instantiated_Sut
            {
                #region Context

                private IX509ChainElementCollection Result { get; set; }

                protected override void EstablishContext()
                {
                    base.EstablishContext();
                }

                protected override sealed void Because()
                {
                    this.Result = this.Sut.Create();
                }

                #endregion

                [Test]
                public void then_Result_is_not_null()
                {
                    NUnit.Framework.Assert.NotNull(this.Result);
                }
            }

            public sealed class when_Create_is_called : given_instantiated_Sut
            {
                #region Context

                private static readonly byte[] LiebherrRootCaCertificateRawCertData =
                    {
                        0x30, 0x82, 0x03, 0x9a, 0x30, 0x82, 0x02, 0x82, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x61, 0xf4, 0x7b, 0x45, 0x74, 0xf8,
                        0xc3, 0x9f, 0x4e, 0x0c, 0xed, 0xa8, 0x00, 0xda, 0x3d, 0xd3, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
                        0x01, 0x05, 0x05, 0x00, 0x30, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x44, 0x45, 0x31, 0x11,
                        0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x4c, 0x69, 0x65, 0x62, 0x68, 0x65, 0x72, 0x72, 0x31, 0x11, 0x30, 0x0f,
                        0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x08, 0x5a, 0x45, 0x44, 0x56, 0x2d, 0x4f, 0x52, 0x47, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03,
                        0x55, 0x04, 0x03, 0x13, 0x0e, 0x4c, 0x69, 0x65, 0x62, 0x68, 0x65, 0x72, 0x72, 0x52, 0x6f, 0x6f, 0x74, 0x43, 0x41, 0x30, 0x1e,
                        0x17, 0x0d, 0x30, 0x39, 0x31, 0x30, 0x32, 0x36, 0x31, 0x30, 0x30, 0x37, 0x34, 0x37, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x31, 0x30,
                        0x32, 0x36, 0x31, 0x30, 0x31, 0x37, 0x34, 0x37, 0x5a, 0x30, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
                        0x02, 0x44, 0x45, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x4c, 0x69, 0x65, 0x62, 0x68, 0x65, 0x72,
                        0x72, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x08, 0x5a, 0x45, 0x44, 0x56, 0x2d, 0x4f, 0x52, 0x47, 0x31,
                        0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0e, 0x4c, 0x69, 0x65, 0x62, 0x68, 0x65, 0x72, 0x72, 0x52, 0x6f, 0x6f,
                        0x74, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
                        0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xbf, 0x15, 0x9e, 0xde, 0xf7, 0xe7,
                        0x18, 0x89, 0x86, 0xc8, 0x20, 0xb8, 0x36, 0x42, 0x36, 0x02, 0x1c, 0xa8, 0x1c, 0x17, 0xe6, 0x09, 0x47, 0x48, 0xb1, 0xa8, 0x09,
                        0xd7, 0x36, 0x7c, 0xb3, 0x24, 0xb3, 0xd6, 0x25, 0xf6, 0x21, 0xc8, 0x02, 0xbc, 0x76, 0xd2, 0xf6, 0x7a, 0xbd, 0x46, 0x0b, 0xfc,
                        0xb1, 0x72, 0x5a, 0x5f, 0x89, 0xfe, 0xe2, 0x5e, 0xfb, 0xcd, 0x66, 0x46, 0xc3, 0x49, 0x4f, 0x47, 0xd5, 0xa8, 0x62, 0xb4, 0x37,
                        0x18, 0x24, 0x21, 0x32, 0x62, 0xfe, 0xaa, 0x20, 0xe4, 0x8b, 0xf8, 0x63, 0x00, 0x0d, 0xa1, 0x79, 0xb7, 0xa8, 0x69, 0xad, 0xf0,
                        0x54, 0x0a, 0xcb, 0x5d, 0x98, 0x2f, 0x4f, 0x6e, 0xe6, 0x6b, 0x04, 0xd9, 0xc3, 0xfc, 0xc3, 0x58, 0x21, 0x96, 0xca, 0xa7, 0x46,
                        0x12, 0xf2, 0x64, 0x4d, 0x2a, 0x6c, 0x25, 0x4d, 0x0e, 0x28, 0x37, 0x4c, 0x84, 0x2f, 0x6c, 0x16, 0x0f, 0xc9, 0x79, 0xce, 0x0c,
                        0x50, 0x7a, 0x33, 0xe3, 0x39, 0xdc, 0x91, 0x62, 0xd1, 0x44, 0x41, 0xee, 0xe4, 0x8f, 0x86, 0xab, 0xe1, 0x74, 0xe8, 0x05, 0xad,
                        0xd1, 0xa2, 0x11, 0x9f, 0x8b, 0x01, 0xe9, 0x80, 0xb9, 0x92, 0xe2, 0x04, 0x93, 0x04, 0x6a, 0xe7, 0xcd, 0x59, 0x9c, 0x46, 0xcc,
                        0x60, 0x18, 0x2e, 0x2a, 0x46, 0xd3, 0x52, 0xb3, 0xe0, 0x1f, 0x93, 0xb2, 0x77, 0x5a, 0x38, 0x8e, 0x78, 0x25, 0xaf, 0x88, 0xf3,
                        0x92, 0xdc, 0xe6, 0xae, 0x97, 0x07, 0x0f, 0x84, 0x2c, 0xbe, 0xfb, 0x65, 0x57, 0x95, 0x57, 0x37, 0x57, 0x2e, 0x56, 0x7a, 0xa6,
                        0xed, 0x7b, 0x13, 0x98, 0x1d, 0x3d, 0x59, 0x66, 0x5f, 0x58, 0x7a, 0xc7, 0x3c, 0x6a, 0xa5, 0xf0, 0xff, 0x23, 0x1c, 0x12, 0x0d,
                        0x80, 0x65, 0xe5, 0xc9, 0x8a, 0x8a, 0x0b, 0xb6, 0x7f, 0xe1, 0xc2, 0xeb, 0xe5, 0x19, 0x61, 0x9a, 0x64, 0x1c, 0x13, 0x02, 0x03,
                        0x01, 0x00, 0x01, 0xa3, 0x78, 0x30, 0x76, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x01, 0x86, 0x30,
                        0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55,
                        0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x74, 0xe0, 0xc4, 0xfb, 0x95, 0xf2, 0x48, 0x78, 0x1a, 0x17, 0xe2, 0x14, 0xcb, 0xb0, 0x83,
                        0x03, 0xe8, 0xf9, 0xf7, 0xb5, 0x30, 0x12, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x15, 0x01, 0x04, 0x05, 0x02,
                        0x03, 0x02, 0x00, 0x02, 0x30, 0x23, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x15, 0x02, 0x04, 0x16, 0x04, 0x14,
                        0xef, 0x3c, 0x80, 0x54, 0x72, 0x15, 0x38, 0xe5, 0x3a, 0x16, 0xd4, 0x78, 0xe6, 0x05, 0x45, 0x6a, 0x46, 0x6a, 0x4f, 0x9f, 0x30,
                        0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0xaf, 0x22,
                        0x35, 0x04, 0x52, 0x7d, 0xf9, 0xc5, 0x8a, 0x77, 0x25, 0x5e, 0xcf, 0xeb, 0x01, 0x1e, 0x77, 0xa9, 0xb5, 0x79, 0x39, 0x3d, 0x07,
                        0x6e, 0xe4, 0x29, 0x7c, 0x10, 0xae, 0xf6, 0x3f, 0x02, 0x18, 0x57, 0xd4, 0xeb, 0x38, 0x0d, 0x69, 0xd9, 0x3b, 0x7a, 0x58, 0xb1,
                        0xb0, 0x53, 0x21, 0x78, 0x5e, 0x39, 0x0c, 0x8b, 0x5a, 0x30, 0x85, 0x5f, 0xe1, 0x87, 0xdf, 0xf9, 0xb8, 0x8e, 0xad, 0xf1, 0x12,
                        0x2e, 0xf3, 0xef, 0xba, 0x08, 0x2d, 0x6e, 0xba, 0xb4, 0x1a, 0xe1, 0x9a, 0x4c, 0xb9, 0xa7, 0xc9, 0x06, 0xe4, 0x21, 0x64, 0x7a,
                        0x75, 0xaf, 0x82, 0xb9, 0xcb, 0xe2, 0xcd, 0xdd, 0x45, 0x80, 0xb2, 0xb9, 0x19, 0xe2, 0xd2, 0xb1, 0xe9, 0x84, 0xec, 0xc8, 0xca,
                        0x0a, 0x06, 0xa3, 0x36, 0xfb, 0x64, 0xae, 0x4a, 0xc8, 0xe7, 0x80, 0xd6, 0x15, 0xa0, 0xa1, 0xa7, 0x89, 0x3b, 0x77, 0x3f, 0x3b,
                        0x3f, 0xb8, 0x84, 0x84, 0xd7, 0xc4, 0x15, 0xcb, 0x11, 0x59, 0x2f, 0xa9, 0x27, 0x50, 0xd9, 0xde, 0x16, 0x99, 0x78, 0xad, 0x87,
                        0xef, 0x40, 0x61, 0x71, 0x59, 0xc2, 0xd9, 0x1f, 0xa9, 0xa8, 0xee, 0xbc, 0xaf, 0x57, 0xe1, 0xb9, 0xfa, 0x51, 0xbf, 0x94, 0x59,
                        0x7a, 0x5e, 0x3a, 0x3b, 0xfe, 0x27, 0x9b, 0x52, 0x8b, 0x23, 0x50, 0xfa, 0x94, 0x4e, 0x37, 0x73, 0x0c, 0x5e, 0x48, 0x4c, 0x72,
                        0x16, 0xe1, 0xb4, 0x34, 0x37, 0x5d, 0x24, 0x9e, 0xba, 0xd6, 0x57, 0x50, 0xea, 0x86, 0x1a, 0x50, 0x82, 0x6a, 0xf8, 0x60, 0x59,
                        0x50, 0x72, 0xd4, 0xcb, 0xf9, 0xb5, 0x30, 0x5a, 0xf1, 0xc6, 0xb5, 0x0b, 0x11, 0x7f, 0x9f, 0xac, 0xde, 0x8c, 0xf3, 0x2b, 0xaa,
                        0xd5, 0xb2, 0x44, 0x81, 0x45, 0xf0, 0x75, 0xd8, 0x65, 0xfd, 0x1c, 0x03, 0xa3, 0x58, 0xa2, 0x22, 0xb8, 0x64, 0x33, 0x2d, 0x57,
                        0xe8, 0xc8
                    };

                private int ExpectedCount { get; set; }

                private IX509ChainElementCollection Result { get; set; }

                private X509ChainElementCollection SpecifiedCollection { get; set; }

                protected override void EstablishContext()
                {
                    base.EstablishContext();

                    var collection = new X509Chain();
                    collection.Build(new X509Certificate2(LiebherrRootCaCertificateRawCertData));
                    this.SpecifiedCollection = collection.ChainElements;

                    this.ExpectedCount = 1;
                }

                protected override sealed void Because()
                {
                    this.Result = this.Sut.Create(this.SpecifiedCollection);
                }

                #endregion

                [Test]
                public void then_Result_is_not_null()
                {
                    NUnit.Framework.Assert.NotNull(this.Result);
                }

                [Test]
                public void then_Result_Count_matches_ExpectedCount()
                {
                    NUnit.Framework.Assert.AreEqual(this.ExpectedCount, this.Result.Count);
                }
            }
        }
    }
}